<?php include("src/addLibranza_cs.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href='css/coolMessage.css' type='text/css' rel='stylesheet' media='screen' />
<title>Adicionar Libranza :: ASSC</title>
<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript" src="js/jquery.simplemodal.js"></script>
<script language="javaScript" type="text/javascript" src="js/coolMessage.js"></script>

<link rel="stylesheet" type="text/css" media="all" href="includes/calendario/calendar-system.css" title="system" />
<script type="text/javascript" src="includes/calendario/calendar.js"></script>
<script type="text/javascript" src="includes/calendario/lang/calendar-es.js"></script>
<script type="text/javascript" src="includes/calendario/calendar-setup.js"></script>
	<script type="text/javascript" src="js/ajax.js"></script>
	<script type="text/javascript" src="js/ajax-dynamic-list-company.js"></script>

<script language="javascript" type="text/javascript">
	
	var displayRow = '';
	if (navigator.appName == "Netscape")
		displayRow = 'table-row';
	else if (navigator.appName.indexOf("Explorer") != -1) 
		displayRow = 'block';
		
 $(document).ready(loadEmployed());
 function loadEmployed()
	{
		var code = document.getElementById("country").value;
		$.ajax({
			type: "POST",
			url: "loadEmployed.php",
			data: 'code='+code,
			success: function(msg)
			{
				document.getElementById('divstates').innerHTML = '<select name="code" id="code">'+msg+'</selected>';		
			}
			
			});
		
	}		
	

	function validate(action){

		document.getElementById("action").value = action;//1: save, 2: save and continue.
		
		var msg = '';
		var hdvc_code 		= document.getElementById("country").value;
		var hdv_code 		= document.getElementById("code").value;
		var lib_value  			= document.getElementById("lib_value").value;
		var lib_interes  			= document.getElementById("lib_interes").value;
		var lib_month  			= document.getElementById("lib_month").value;
		var lib_date_start   		= document.getElementById("lib_date_start").value;
			
		if(hdvc_code == '') 
			msg='- Por favor entre la compania. <br />';
			
		if(hdv_code == '') 
			msg='- Por favor entre el empleado. <br />';
		
		if(lib_value == '') 
			msg='- Por favor entre el valor de la libranza. <br />';
			
		if(lib_interes == '') 
			msg='- Por favor entre el interes. <br />';
			
		if(lib_month == '') 
			msg= msg+'- Por favor entre los meses. <br />';
			
		if(lib_date_start == '') 
			msg= msg+'- Por favor entre la fecha de comenzar a pagar. <br />';
		
		if(msg==''){
			document.getElementById('form').submit();

			return true;
		}
		else{
			coolMessage("alert", msg);
			return false;
		}		
	}
	

	function onlyNumbers(e)
	{
	   var key;
	   if(window.event)
		  key = window.event.keyCode;   //IE
	   else
		  key = e.which;                //firefox
	   if (!( (key >= 48 && key <= 57) || key ==8 || key ==9 || key ==0 || key ==46 ))
		  return false;
	   else
		  return true;
	}	
	
	function validateTotalValue(){

	if(document.getElementById('lib_value').value != '' || document.getElementById('lib_value').value != 0)
		var new_lib_value = document.getElementById('lib_value').value;
	else{
		var new_lib_value = 0;
		var total_payment = 0;
	}
	
	if (document.getElementById('lib_interes').value == '' && document.getElementById('lib_month').value == '' && document.getElementById('lib_cuotas_pago').value =='' ){
	
	var total = new_lib_value;
	var total_interes = 0;
	
	}
	else {

	if(document.getElementById('lib_interes').value != '' || document.getElementById('lib_interes').value != 0 )
		var new_interes = document.getElementById('lib_interes').value;

	else
		var new_interes = 1;	

	if(document.getElementById('lib_month').value != '' || document.getElementById('lib_month').value != 0 )
		var new_month = document.getElementById('lib_month').value;
	else
		var new_month = 1;
		
	if(document.getElementById('lib_cuotas_pago').value != '' || document.getElementById('lib_cuotas_pago').value != 0 )
		var new_payment = document.getElementById('lib_cuotas_pago').value;
	else
		var new_payment = 1;	


		var total_interes = (parseFloat(new_lib_value)*parseFloat(new_interes))*parseFloat(new_month);
		var total = parseFloat(new_lib_value)+parseFloat(total_interes);
		
		var total_payment = (parseFloat(total)/parseFloat(new_payment));
			
	}
	
	document.getElementById("content_interes").innerHTML = parseFloat(total_interes);	 	
	document.getElementById("content_value_loan").innerHTML = parseFloat(total);
	
	document.getElementById("content_balance").innerHTML = parseFloat(total);
	document.getElementById("content_payment").innerHTML =  parseFloat(total_payment.toFixed(2));
	
	document.getElementById('lib_total').value = parseFloat(total);
	document.getElementById('lib_amount_payment').value = parseFloat(total_payment.toFixed(2));
	document.getElementById("lib_balance").value = parseFloat(total);
		
	}

	
</script>
</head>
<body>
<?php $item_select = 14;include("menu.php");?><br />
    <form name="form" id="form" method="post" action="" enctype="multipart/form-data">
    <input type="hidden" name="addLibranza" id="addLibranza" value="1"/>
	<input type="hidden" name="action" id="action" value="1"/>
    <input type="hidden" name="hdvc_code" id="hdvc_code" />
    <input type="hidden" name="hdv_code" id="hdv_code" />
    <input type="hidden" name="lib_total" id="lib_total" />
    <input type="hidden" name="lib_amount_payment" id="lib_amount_payment" />
    <input type="hidden" name="lib_balance" id="lib_balance" />
    
    
    <div class="content_grv">
		<table width="80%" align="center" class="shadow">
            <tr>
                <td class="title">Informacion Prestamo Empleado</td>
            </tr>
            <tr>
                <td>
                    <table class="tbl_form" align="center">
						<tr>
                            <td align="right"><span class="lbl_gray">Compania :</span></td>
                            <td><div id="div_company"></div></td>
                            <td><select name="country" id="country" onchange="javascript: loadEmployed()">
                        <option value="">Seleccione..</option>
                        <?php echo utf8_encode($company);?>
                      </select></td>
        					<td align="left"></td>
                            <td></td>
                            
                        </tr>

                        <tr>
                            <td align="right"><span class="lbl_gray">Empleado:</span></td>
                            <td>&nbsp;</td>
                            <td  id="divstates">
                        <select name="code" id="code">
                          <option value="">Seleccione..</option>
                          <?php echo utf8_encode($employed);?>
                        </select>
                      </td>
                        </tr>
                        <tr>
                        <tr>
                            <td width="35%" align="right"><span class="lbl_gray">Valor Prestamo:</span></td>
                            <td width="1%"> $ </td>
                            <td><input type="text" name="lib_value" id="lib_value" class="text_grv" size="31" maxlength="30" onKeyPress="return onlyNumbers(event)" onkeyup="javascript: validateTotalValue(this.value)"/></td>
                        </tr>
                        <tr>
                            <td width="35%" align="right"><span class="lbl_gray">Tasa Interes:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td><input type="text" name="lib_interes" id="lib_interes" class="text_grv" size="21" maxlength="20" onKeyPress="return onlyNumbers(event)" onkeyup="javascript: validateTotalValue(this.value)" /></td>
                        </tr>
                        <tr>
                            <td width="35%" align="right"><span class="lbl_gray">Meses Prestamo:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td><input type="text" name="lib_month" id="lib_month" class="text_grv" size="11" maxlength="10" onKeyPress="return onlyNumbers(event)" onkeyup="javascript: validateTotalValue(this.value)"/></td>
                        </tr>
                        <tr>
                            <td width="35%" align="right"><span class="lbl_gray">Total Interes:</span></td>
                            <td width="1%"> $ </td>
                            <td id="content_interes"></td>
                        </tr>
                        <tr>
                            <td width="35%" align="right"><span class="lbl_gray">Total Prestamo:</span></td>
                            <td width="1%"> $ </td>
                            <td id="content_value_loan"></td>
                        </tr>
                        <tr>
                            <td width="35%" align="right"><span class="lbl_gray">Coutas pago:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td><input type="text" name="lib_cuotas_pago" id="lib_cuotas_pago" class="text_grv" size="11" maxlength="10" onKeyPress="return onlyNumbers(event)" onkeyup="javascript: validateTotalValue(this.value)"/></td>
                        </tr>
                        <tr>
                            <td width="35%" align="right"><span class="lbl_gray">cantidad a Pagar:</span></td>
                            <td width="1%"> $ </td>
                            <td id="content_payment"></td>
                        </tr>
                       <tr>
                            <td align="right"><span class="lbl_gray">Fecha Inicio Pago:</span></td>
                            <td>&nbsp;</td>
                            <td><input name="lib_date_start" type="text" style="width:100px" readonly="readonly" id="lib_date_start" maxlength="45" class="text_grv"
				value="<?php if(isset($lib_date_start)) echo $lib_date_start?>"/>
			    <input name="imagea" type="image" id="calendar1" src="images/mostrar_calendario.png" align="absmiddle" width="18" height="16"/></td>
				<script type="text/javascript">
						Calendar.setup({
						inputField : "lib_date_start",							
						ifFormat : "%Y/%d/%m",
						showsTime : false,
						button : "calendar1", 
						step : 1
						});
				</script>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Fecha de Terminacion:</span></td>
                            <td>&nbsp;</td>
                            <td><input name="lib_date_end" type="text" style="width:100px" readonly="readonly" id="lib_date_end" maxlength="45" class="text_grv"
				value="<?php if(isset($lib_date_end)) echo $lib_date_end?>"/>
			    <input name="imagea" type="image" id="calendar2" src="images/mostrar_calendario.png" align="absmiddle" width="18" height="16"/></td>
				<script type="text/javascript">
						Calendar.setup({
						inputField : "lib_date_end",							
						ifFormat : "%Y/%d/%m",
						showsTime : false,
						button : "calendar2", 
						step : 1
						});
				</script>
                        </tr>
                         <tr>
                            <td width="35%" align="right"><span class="lbl_gray">Balance:</span></td>
                            <td width="1%"> $ </td>
                            <td id="content_balance"></td>
                        </tr>
                        <tr>
                            <td valign="top" align="right"><span class="lbl_gray">Descripcion:</span></td>
                            <td>&nbsp;</td>
                            <td><textarea name="lib_description" id="lib_description" class="text_grv" cols="40" rows="7"></textarea></td>
                        </tr>
                        <tr>
                            <td colspan="3" align="center">&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="3" align="center">
                                <input type="button" class="button_grv" value="Save" onclick="javascript: return validate(1);" />
                                <input type="button" class="button_grv" value="Save and continue" onclick="javascript: return validate(2);" />
                                <input type="reset" value="Reset" class="button_grv_cancel"/>
                                <input type="button" class="button_grv_cancel" value="Cancel" onClick="javascript:window.location.href='listEmployed.php';" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
 	</div>
</form>    
</body>
</html>
<?php include('divscoolmessage.php');?>
